import requests
import time
import hmac
import hashlib
"""

API密钥
oMlYVBgANplqH7XilK0rzJ47r7p1R3MWoywVNBYOGvj5UHYXebQnxZjX9kLpdd5V
密钥:
8587vRjV45QsPPXhlrn3vcBdUwQJFA6HIBqfaVbJO7UqhhqTcVrQCR4GEO6w4OtN
"""
api_key = "oMlYVBgANplqH7XilK0rzJ47r7p1R3MWoywVNBYOGvj5UHYXebQnxZjX9kLpdd5V"
secret_key = "8587vRjV45QsPPXhlrn3vcBdUwQJFA6HIBqfaVbJO7UqhhqTcVrQCR4GEO6w4OtN"

# 生成签名
timestamp = int(time.time() * 1000)
params = {
    "timestamp": timestamp,
    "recvWindow": 5000  # 请求超时时间（毫秒）
}

query_string = "&".join([f"{k}={v}" for k, v in params.items()])
signature = hmac.new(secret_key.encode(), query_string.encode(), hashlib.sha256).hexdigest()

# 发送请求
url = "https://api.binance.com/api/v3/account"
headers = {
    "X-MBX-APIKEY": api_key
}
params["signature"] = signature

response = requests.get(url, headers=headers, params=params)
print(response.json())